package com.yyn.pigeon.controller;


import com.yyn.pigeon.config.R;
import com.yyn.pigeon.entity.User;
import com.yyn.pigeon.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author yyn
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/pigeon/user")
public class UserController {
@Autowired
    private UserService userService;
    @ApiOperation("登录")
    @PostMapping("login")
    public R login(@RequestBody User user){
        User user1 = userService.login(user);
        if(user1==null){
            return R.error().message("登录失败");
        }

            return R.success().data("user",user1);
    }

    @ApiOperation("注册")
    @PostMapping("register")
    public R register(@RequestBody User user){
        Boolean register = userService.register(user);
        if(register){
            R.success().data("msg","注册成功");
        }else {
            R.error().data("msg", "该手机号已注册请登录");
        }
        return null;
    }
}

